#ifndef VIRTUAL_DRIVER_H
#define VIRTUAL_DRIVER_H

#include "typedef.h"
#define LCR_VM  0x00 
#define LRC_VM_SIZE     0x7000

#define COMVAL_VM_SIZE 0x400 
#define COMVAL_VM      1 


////2M
//#ifdef FRONT_GBK
//#define	BLOCK_BASEADDR		(u32)0x1B0000
//#else
//#define	BLOCK_BASEADDR		(u32)0x1B0000
//#endif

//4M
#ifdef FRONT_GBK
#define	BLOCK_BASEADDR		(u32)0x3B0000
#else
#define	BLOCK_BASEADDR		(u32)0x3B0000
#endif

#define VMBLOCK_COUNT		5
#define PAGE_SIZE			256		
#define MAX_VMCOUNT			3
#define BLOCK_SIZE			((u32)0x10000)
#define BLOCK_ENDADDR		((u32)BLOCK_BASE+((u32)BLOCK_COUNT<<16))
#define BLOCK_INDEX1		0x56
#define BLOCK_INDEX2		0xaa
#define WRITE_END			0x66

#define BLOCK_ADDR(addr)	(((u32)(addr)>>16)<<16)
#define GET_SMALL(a,b)		(((a)<(b))?(a):(b))
typedef struct 
{
	u8  xdata *lpdata;
	u16  len;
	u32  writeaddr;
	u32  readaddr;
	u32  log_addr;
}DATA_MOVE;
typedef struct
{
	u8  nomove;
	u16 vm_size;
	u16 ptr;
	u32 curr_addr;	
}VMINFO;


extern u8 xdata *  pBuf;
extern  u8 xdata *  pBuf2; 
extern  u32 xdata index_addr;
extern  u32 xdata BLOCK_BASE;
extern  u8  xdata  BLOCK_COUNT;


extern VMINFO xdata vminfo[MAX_VMCOUNT];



void VM_init(u8 xdata *buf ,u32 xdata block_base,u32 block_count) large ;
void VM_SetSize(u32 size,u8 num,u8 no_move)large ;
void VMRead(u8 xdata *spidata,u32 xdata address,u16 xdata len,u8 num)large ;
void VMWrite(u8 xdata *spidata,u32 xdata address,u16 xdata len,u8 num)large ;
void  Updata_addr()large;
void write_addrtoIndex(u8 num)large ;
void spiFlashPageWrite(u8 xdata *spidata,u32 xdata   address,u16 xdata  len) large ;

u8  Get_UnusedBlock(u32 xdata *address)large ; 

void spi_delay(u8 i) large ;
u8 FlashBlockEraser(u32 xdata addr)  large ;
void  copyData(DATA_MOVE xdata *lpmov,u32 xdata len,u8 isread) large ;







#endif